import 'dart:async';

import 'package:hongsheng/api/SPClassApiManager.dart';
import 'package:hongsheng/api/SPClassHttpCallBack.dart';
import 'package:hongsheng/api/SPClassNetConfig.dart';
import 'package:hongsheng/app/SPClassApplicaion.dart';
import 'package:hongsheng/model/SPClassBannerItem.dart';
import 'package:hongsheng/model/SPClassGuessMatchInfo.dart';
import 'package:hongsheng/model/SPClassNoticesNotice.dart';
import 'package:hongsheng/pages/anylise/SPClassExpertDetailPage.dart';
import 'package:hongsheng/pages/common/SPClassShareView.dart';
import 'package:hongsheng/pages/competition/SPClassMatchDetailPage.dart';
import 'package:hongsheng/pages/competition/scheme/SPClassExpertApplyPage.dart';
import 'package:hongsheng/pages/competition/scheme/SPClassSchemeDetailPage.dart';
import 'package:hongsheng/pages/dialogs/SPClassHomeFilterMatchDialog.dart';
import 'package:hongsheng/pages/home/SPClassNoticeWidget.dart';
import 'package:hongsheng/pages/news/SPClassWebPageState.dart';
import 'package:hongsheng/pages/user/SPClassContactPage.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassDateUtils.dart';
import 'package:hongsheng/utils/SPClassImageUtil.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/utils/SPClassStringUtils.dart';
import 'package:hongsheng/utils/colors.dart';
import 'package:hongsheng/widgets/SPClassNestedScrollViewRefreshBallStyle.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';

import '../../widgets/nested_scroll_view_inner_scroll_position_key_widget.dart';
import 'SPClassHomeSchemeList.dart';
import 'SPClassTabHotExpert.dart';

class SPClassHomePage extends StatefulWidget{
  SPClassHomePageState ?spProState;
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return spProState= SPClassHomePageState();
  }

}


class SPClassHomePageState extends State<SPClassHomePage> with
    AutomaticKeepAliveClientMixin<SPClassHomePage>,TickerProviderStateMixin<SPClassHomePage>{
  List banners = [];
  TabController ?spProTabSchemeController;
  TabController ?spProTabMatchController;   //顶部导航栏
  PageController ?spProPageControlller;
  ScrollController ?spProMsgScrollController;
  ScrollController ?spProHomeScrollController;
  List<SPClassNoticesNotice> notices = []; //公告列表
  static String spProHomeMatchType = "足球";
  static String spProHomeMatchTypeKey = "is_zq_expert";
  bool spProShowTitle = false;
  bool spProShowTopView = false;
  var spProTabMatchTitles=["关注","足球专家","篮球专家"];
  var spProTabMatchKeys=["关注","足球","篮球"];
  List spProTabSchemeTitles = ["高胜率","最新",  "免费"];
  List spProTabSchemeKeys = ["recent_correct_rate","newest",  "free"];
  var spProTabExpertKeys=["关注","is_zq_expert","is_lq_expert","is_es_expert"];
  List<SPClassGuessMatchInfo> ?spProHotMatch =[];//热门赛事
  String spProPayWay = "";
  var spProReFreshTime;
  List<SPClassHomeSchemeList> spProSchemeViews = [];
  List<SPClassTabHotExpert> spProTabHotViews = [];
  GlobalKey spProKeyTopTitle = GlobalKey();
  GlobalKey spProKeyBannerItem = GlobalKey();
  double spProTopOffset = 0.0;
  double spProHeightNoticeItem = 0.0;
  int spProTabSchemeIndex = 0;
  int spProTabMatchIndex = 1; //顶部栏的下标
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // spFunGetHotMatch();
    spProMsgScrollController = ScrollController(initialScrollOffset: width(25));
    spProHomeScrollController = ScrollController();
    spProTabSchemeController = TabController(length: spProTabSchemeTitles.length, vsync: this, initialIndex: 1);
    spProTabMatchController=TabController(length: spProTabMatchTitles.length,vsync: this,initialIndex: 1);

    // (
    // spFunIsLogin() &&
    // SPClassApplicaion.spProUserLoginInfo!.spProIsFirstLogin!)
    // ? 2
    // : 0)
    // ;
    spProSchemeViews = spProTabSchemeKeys.map((key) {
      return SPClassHomeSchemeList(
        spProFetchType: key,
        spProPayWay: spProPayWay,
        spProShowProfit: key != "recent_correct_rate",
        // type: widget.type,
      );
    }).toList();
    spProTabHotViews=spProTabExpertKeys.map((key)=>  SPClassTabHotExpert(key)).toList();
    spProPageControlller = PageController();
    Timer.periodic(Duration(seconds: 2), (timer){
      if(spProMsgScrollController!.positions.isNotEmpty){
        spProMsgScrollController!.animateTo(spProMsgScrollController!.offset+20, duration: Duration(seconds: 2), curve: Curves.linear);
      }
    });
    spProTabMatchController!.addListener((){
      if(spProTabMatchIndex==spProTabMatchController!.index){
        return;
      }
      spProTabMatchIndex=spProTabMatchController!.index;
      setState(() {});
      spProHomeMatchType= spProTabMatchKeys[spProTabMatchController!.index];
      spProHomeMatchTypeKey= spProTabExpertKeys[spProTabMatchController!.index];
      SPClassApplicaion.spProEventBus.fire("scheme:refresh"+
          "${spProTabMatchKeys[spProTabMatchController!.index]}");
    });
    spFunGetBannerList();
    spFunGetNotices();
    spProHomeScrollController?.addListener((){
      if(spProHomeScrollController!.offset>=((kToolbarHeight+MediaQuery.of(context).padding.top)*0.8)){
        if(!spProShowTitle){
          if(mounted){setState(() {spProShowTitle=true;});}
        }
      }else{
        if(spProShowTitle){
          if(mounted){setState(() {spProShowTitle=false;});}
        }
      }

      if(spProHomeScrollController!.offset>(spProTopOffset)){
        if(!spProShowTopView){
          if(mounted){setState(() {spProShowTopView=true;});}
        }
      }else{
        if(spProShowTopView){
          if(mounted){setState(() {spProShowTopView=false;});}
        }
      }
    });

    SPClassApplicaion.spProEventBus.on<String>().listen((event) {
      if (event == "loginInfo") {
        // getSeqNum();
        // if (spFunIsLogin() &&
        //     SPClassApplicaion.spProUserLoginInfo.spProIsFirstLogin) {
        //   spProTabSchemeController.index = 2;
        // }
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    final double statusBarHeight = MediaQuery.of(context).padding.top;
    return Scaffold(
      floatingActionButton: AnimatedContainer(
        duration: Duration(milliseconds: 200),
        child: !spProShowTopView ?SizedBox():
        GestureDetector(
          child: Container(
            padding: EdgeInsets.all(width(4)),
            decoration: ShapeDecoration(
              shape: CircleBorder(side: BorderSide(color: Color(0xFF666666),width: 0.4)),
            ),
            child: Icon(Icons.vertical_align_top,color: Color(0xFF666666),size: width(25),),
          ),
          onTap: (){
            spFunScrollTop();
          },
        ),
      ),
      body: Stack(
        children: [
          Container(
            color: Color(0xFFF1F1F1),
            child: SPClassNestedScrollViewRefreshBallStyle(
              onRefresh: () {
                spFunGetBannerList();
                spFunGetNotices();
                // spFunGetHotMatch();

                spProTabHotViews[spProTabMatchController!.index].spProState!.onRefresh();
                return spProSchemeViews[spProTabSchemeController!.index]
                    .spProState!
                    .spFunOnRefresh(spProPayWay,
                    spProHomeMatchType);
              },
              child: ExtendedNestedScrollView(
                controller: spProHomeScrollController!,
                headerSliverBuilder:
                    (BuildContext context, bool boxIsScrolled) {
                  return <Widget>[
                    SliverAppBar(
                      elevation: 0,
                      pinned: false,
                      brightness: Brightness.light,
                      forceElevated: boxIsScrolled,
                      expandedHeight: width(133),
                      backgroundColor:Theme.of(context).primaryColor,
                      flexibleSpace:FlexibleSpaceBar(
                        collapseMode: CollapseMode.pin,
                        background: Container(
                          color: Colors.white,
                          width: MediaQuery.of(context).size.width,
                          height: width(166),
                          child: banners.length==0 ?SizedBox():Stack(
                            alignment: Alignment.center,
                            children: <Widget>[
                              Container(
                                child:  Swiper(
                                  itemBuilder: (BuildContext context, int index) {
                                    return Image.network(
                                      banners[index].spProImgUrl,
                                      width: MediaQuery.of(context).size.width,
                                      height:width(166),
                                      fit: BoxFit.fill,
                                    );
                                  },
                                  onTap:(index){
                                    if(spFunIsLogin(context: context)){
                                      SPClassApiManager.spFunGetInstance().spFunLogAppEvent(spProEventName: "view_banner",targetId:banners[index].spProBannerId);
                                      spFunGoRoutPage(banners[index].spProPageUrl, banners[index].title,null,false);
                                    }

                                  } ,
                                  itemCount: banners.length,
                                  viewportFraction: 1,
                                  scale: 1,
                                  autoplay: (banners.length>1)? true:false,
                                ),
                              ),
                              Positioned(
                                  right: 0,
                                  left: 0,
                                  bottom: 0,
                                  child: SPClassNoticeWidget(notices: notices,))
                            ],
                          ),
                        ),
                      ),
                    ),
                    SliverToBoxAdapter(
                      child:Container(
                        height: width(37),
                        color: Colors.white,
                        child: TabBar(
                          labelColor: Color(0xFFE3494B),
                          labelPadding: EdgeInsets.zero,
                          unselectedLabelColor: Color(0xFF333333),
                          indicatorColor: Colors.red[500],
                          isScrollable: false,
                          indicatorSize:TabBarIndicatorSize.label,
                          unselectedLabelStyle:TextStyle(fontSize: sp(14),),
                          labelStyle: TextStyle(fontSize: sp(14),fontWeight: FontWeight.w600),
                          controller: spProTabMatchController,
                          tabs:spProTabMatchTitles.map((key){
                            return    Tab(text: key,);
                          }).toList() ,
                        ),
                      ),
                    ),
                    SliverToBoxAdapter(
                      child: IndexedStack(
                        index: spProTabMatchController!.index,
                        children: spProTabHotViews,
                      ),
                    ),
                  ];
                },
                pinnedHeaderSliverHeightBuilder: (){
                  return MediaQuery.of(context).padding.top;
                },
                // innerScrollPositionKeyBuilder: () {
                //   var index = "homeTab";
                //   index += spProTabSchemeController!.index.toString();
                //   return Key(index);
                // },
                body: Container(
                  margin: EdgeInsets.only(left: width(10),right: width(10)),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      boxShadow:[
                        BoxShadow(
                          offset: Offset(2,5),
                          color: Color(0x0C000000),
                          blurRadius:width(6,),),
                        BoxShadow(
                          offset: Offset(-5,1),
                          color: Color(0x0C000000),
                          blurRadius:width(6,),
                        )
                      ],
                      borderRadius: BorderRadius.circular(width(7))
                  ),
                  child: Column(
                    children: <Widget>[
                      GestureDetector(
                        child: Container(
                          key: spProKeyTopTitle,
                          padding: EdgeInsets.only(left: width(13),right: width(13)),
                          height:width(35),
                          decoration: BoxDecoration(
                              border: Border(bottom: BorderSide(width: 0.4,color: Colors.grey[300]!))
                          ),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: <Widget>[
                              Container(
                                width: height(4),
                                height: height(14),
                                decoration: BoxDecoration(
                                    color: Color(0xFFDE3C31),
                                    borderRadius: BorderRadius.circular(100)
                                ),
                              ),
                              SizedBox(width: 4,),
                              Text("赛事分析",style: TextStyle(fontWeight: FontWeight.w500,fontSize: sp(15)),),
                              Expanded(child: SizedBox(),),
                              Container(
                                width: width(47.0*spProTabSchemeTitles.length),
                                child:TabBar(
                                  labelColor: Color(0xFFE3494B),
                                  labelPadding: EdgeInsets.zero,
                                  unselectedLabelColor: Color(0xFF666666),
                                  indicatorColor: Colors.red[500],
                                  isScrollable: false,
                                  indicatorSize:TabBarIndicatorSize.label,
                                  labelStyle: TextStyle(fontSize: sp(13),fontWeight: FontWeight.bold),
                                  unselectedLabelStyle:  TextStyle(fontSize: sp(13)),
                                  controller: spProTabSchemeController,
                                  tabs:spProTabSchemeTitles.map((tab){
                                    return Tab(text: tab,);
                                  }).toList() ,
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(right: width(10),left: width(8)),
                                width: 0.4,
                                color: Colors.grey[300],
                                height: height(19),
                              ),
                              GestureDetector(
                                child: Image.asset(SPClassImageUtil.spFunGetImagePath("ic_filter"),
                                  color: Color(0xFF666666),
                                  width: width(17),
                                ),
                                onTap: (){
                                  showDialog(
                                      context: context,
                                      builder: (BuildContext context) {
                                        return SPClassHomeFilterMatchDialog(
                                                (value) {
                                              spProPayWay = value;
                                              spProSchemeViews[
                                              spProTabSchemeController!
                                                  .index]
                                                  .spProState!
                                                  .spFunOnRefresh(
                                                  spProPayWay,
                                                  spProHomeMatchType);
                                            },
                                            spProHomeMatchType);
                                      });
                                },
                              )

                            ],
                          ),
                        ),
                        onDoubleTap: (){
                          spFunScrollTop();
                        },
                      ),

                      Expanded(
                        child: TabBarView(
                          controller: spProTabSchemeController,
                          children: spProSchemeViews.map((view) {
                            return NestedScrollViewInnerScrollPositionKeyWidget(
                                Key("homeTab" +
                                    spProSchemeViews.indexOf(view).toString()),
                                view);
                          }).toList(),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ),
          ),
          spProShowTitle ?Positioned(
            top: 0,
            right: 0,
            left: 0,
            height: MediaQuery.of(context).padding.top,
            child: Container(
              color: Theme.of(context).primaryColor,
            ),
          ):SizedBox()

        ],
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  Widget matchSchedule(SPClassGuessMatchInfo data){
    return Container(
      height: height(86),
      // margin: EdgeInsets.only(left:width(i==0?14:8),),
      width: width(160),
      decoration: BoxDecoration(
          color: Colors.white,
          boxShadow:[
            BoxShadow(
              offset: Offset(0,0),
              color: Color(0xFFCED4D9),
              blurRadius:width(6,),),
          ],
          borderRadius: BorderRadius.circular(width(8))
      ),
      padding: EdgeInsets.only(left: width(7) ),
      child: Stack(
        children: <Widget>[
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            child:  Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                SizedBox(height: height(4),),
                Row(
                  children: <Widget>[
                    ( data.status=="in_progress" ) ? Text("进行中",style: TextStyle(fontSize: sp(12),color: Color(0xFFFB5146),),):Text(SPClassDateUtils.spFunDateFormatByString(data.spProStTime!, "MM-dd HH:mm"),style: TextStyle(fontSize: sp(11),color: Color(0xFF999999),),maxLines: 1,),
                    Text("「${SPClassStringUtils.spFunMaxLength(data.spProLeagueName!,length: 3)}」",style: TextStyle(fontSize: sp(11),color: Color(0xFF999999),),maxLines: 1,),
                    SizedBox(width: 25,)
                  ],
                ),

                Expanded(
                  child: data.status=="not_started" ?
                  Row(
                    children: <Widget>[
                      Expanded(
                        child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  ClipOval(
                                    child: SPClassImageUtil.spFunNetWordImage(
                                        placeholder: "ic_team_one",
                                        url: data.spProIconUrlOne!,
                                        width: width(17),
                                        height:  width(17)),
                                  ),
                                  SizedBox(width: 5),
                                  Expanded(
                                    child:  Text(data.spProTeamOne!,style: TextStyle(fontSize: sp(13),),maxLines: 1,),
                                  ),
                                  SizedBox(width: width(7),),
                                ],
                              ),
                              SizedBox(height: height(5),),
                              Row(
                                children: <Widget>[
                                  ClipOval(
                                    child: SPClassImageUtil.spFunNetWordImage(
                                        placeholder: "ic_team_two",
                                        url: data.spProIconUrlTwo!,
                                        width: width(17),
                                        height:  width(17)),
                                  ),
                                  SizedBox(width: 5),
                                  Expanded(
                                    child:  Text(data.spProTeamTwo!,style: TextStyle(fontSize: sp(13),),maxLines: 1,),
                                  ),
                                  SizedBox(width: width(7),),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                      Text(
                        '未',
                        style: TextStyle(
                            fontSize: sp(14),
                            color:
                            MyColors.grey_99),
                      ),
                      SizedBox(width: 12,)
                    ],
                  ):
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          ClipOval(
                            child: SPClassImageUtil.spFunNetWordImage(
                                placeholder: "ic_team_one",
                                url: data.spProIconUrlOne!,
                                width: width(17),
                                height:  width(17)),
                          ),
                          SizedBox(width: 5),
                          Expanded(
                            child:  Text(data.spProTeamOne!,style: TextStyle(fontSize: sp(13),),maxLines: 1,),
                          ),
                          Text(data.status=="not_started" ?  "-":data.spProScoreOne!,style: TextStyle(fontSize: sp(13),color:data.status=="in_progress" ? Color(0xFFFB5146): Color(0xFF999999))),
                          SizedBox(width: width(7),),
                        ],
                      ),
                      SizedBox(height: height(5),),
                      Row(
                        children: <Widget>[
                          ClipOval(
                            child: SPClassImageUtil.spFunNetWordImage(
                                placeholder: "ic_team_two",
                                url: data.spProIconUrlTwo!,
                                width: width(17),
                                height:  width(17)),
                          ),
                          SizedBox(width: 5),
                          Expanded(
                            child:  Text(data.spProTeamTwo!,style: TextStyle(fontSize: sp(13),),maxLines: 1,),
                          ),
                          Text(data.status=="not_started" ?  "-":data.spProScoreTwo!,style: TextStyle(fontSize: sp(13),color:data.status=="in_progress" ? Color(0xFFFB5146): Color(0xFF999999))),
                          SizedBox(width: width(7),),
                        ],
                      ),
                    ],
                  ),
                )

              ],
            ),
            onTap: (){
              SPClassApiManager.spFunGetInstance().spFunMatchClick(queryParameters: {"match_id": data.spProGuessMatchId});

              SPClassNavigatorUtils.spFunPushRoute(context, SPClassMatchDetailPage(data,spProMatchType:"guess_match_id",));

            },
          ),
          Positioned(
            right: 0,
            top: 0,
            child:Container(
              width: width(39),
              height: width(17),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.only(bottomLeft: Radius.circular(width(5)),topRight: Radius.circular(width(5))),
                  gradient: LinearGradient(
                      colors: [
                        Color(0xFF1DBDF2),
                        Color(0xFF1D99F2),
                      ]
                  )
              ),
              child: Text('${data.spProSchemeNum}观点',style: TextStyle(color: Colors.white,fontSize: sp(10)),),
            ),
          )
        ],
      ),
    );
  }

  //轮播图
  void spFunGetBannerList() {
    SPClassApiManager.spFunGetInstance().spFunGetBanner<SPClassBannerItem>(
        spProCallBack: SPClassHttpCallBack(spProOnSuccess: (result) {
          setState(() {
            banners = result.spProDataList;
          });
        }),
        queryParameters: {"type": "analysis"});
  }


  void spFunGetNotices() {
    SPClassApiManager.spFunGetInstance().spFunGetNotice<SPClassNoticesNotice>(
        spProCallBack: SPClassHttpCallBack(spProOnSuccess: (notices) {
          if (notices.spProDataList.isNotEmpty) {
            if (mounted) {
              setState(() {
                this.notices = notices.spProDataList;
              });
            }
          }
        }));
  }

  void spFunTabReFresh() {
    if (spProReFreshTime == null ||
        DateTime.now().difference(spProReFreshTime).inSeconds > 30) {
      spFunGetBannerList();
      spFunGetNotices();
      spProTabHotViews[spProTabMatchController!.index].spProState!.onRefresh();
      SPClassTabHotExpert(spProHomeMatchTypeKey).spProState!.onRefresh();
      spProSchemeViews[spProTabSchemeController!.index].spProState!.spFunOnRefresh(spProPayWay,spProTabMatchKeys[spProTabMatchController!.index]);
      spProReFreshTime = DateTime.now();
    }
  }

  void spFunScrollTop() {
    RenderObject? renderBox = spProKeyTopTitle.currentContext!.findRenderObject();

    spProHomeScrollController?.animateTo(0,
        duration: Duration(milliseconds: 500), curve: Curves.linear);
  }

  spFunGoRoutPage(
      String urlPage, String title, String ?spProMsgId, bool isDemo) {
    if (spProMsgId != null) {
      SPClassApiManager.spFunGetInstance().spFunPushMsgClick(
          pushMsgId: spProMsgId,
          isDemo: isDemo,
          spProAutoLoginStr: spFunIsLogin()
              ? SPClassApplicaion.spProUserLoginInfo!.spProAutoLoginStr!
              : "");
    }
    if (urlPage == null || urlPage.trim().isEmpty) {
      return;
    }
    if (urlPage.startsWith("hs_sport:")) {
      Uri url = Uri.parse(urlPage.replaceAll("hs_sport", "hssport"));
      if (urlPage.contains("scheme?")) {
        if (spFunIsLogin(context: context)) {
          SPClassApiManager.spFunGetInstance().spFunSchemeDetail(
              queryParameters: {"scheme_id": url.queryParameters["scheme_id"]},
              context: context,
              spProCallBack: SPClassHttpCallBack(
                  spProOnSuccess: (value) {
                    SPClassNavigatorUtils.spFunPushRoute(
                        context, SPClassSchemeDetailPage(value));
                  },onError: (e){},spProOnProgress: (v){}
              ));
        }
      }
      if (urlPage.contains("expert?")) {
        SPClassApiManager.spFunGetInstance().spFunExpertInfo(
            queryParameters: {"expert_uid": url.queryParameters["expert_uid"]},
            context: context,
            spProCallBack: SPClassHttpCallBack(spProOnSuccess: (info) {
              SPClassNavigatorUtils.spFunPushRoute(
                  context, SPClassExpertDetailPage(info));
            },onError: (e){},spProOnProgress: (v){}
            ));
      }
      if (urlPage.contains("guess_match?")) {
        SPClassApiManager.spFunGetInstance()
            .spFunSportMatchData<SPClassGuessMatchInfo>(
            loading: true,
            context: context,
            spProGuessMatchId: url.queryParameters["guess_match_id"],
            dataKeys: "guess_match",
            spProCallBack:
            SPClassHttpCallBack(spProOnSuccess: (result) async {
              SPClassNavigatorUtils.spFunPushRoute(
                  context,
                  SPClassMatchDetailPage(
                    result,
                    spProMatchType: "guess_match_id",
                    spProInitIndex: 1,
                  ));
            },onError: (e){},spProOnProgress: (v){}
            ));
      }
      if (urlPage.contains("invite")) {
        if (spFunIsLogin(context: context)) {
          SPClassApiManager.spFunGetInstance().spFunShare(
              context: context,
              spProCallBack: SPClassHttpCallBack(spProOnSuccess: (result) {
                showModalBottomSheet<void>(
                    context: context,
                    builder: (BuildContext context) {
                      return SPClassShareView(
                        title: result.title,
                        spProDesContent: result.content,
                        spProPageUrl: result.spProPageUrl ??
                            SPClassNetConfig.spFunGetShareUrl(),
                        spProIconUrl: result.spProIconUrl,
                      );
                    });
              },onError: (e){},spProOnProgress: (v){}
              ));
        }
      }
      if (urlPage.contains("contact_cs")) {
        SPClassNavigatorUtils.spFunPushRoute(context, SPClassContactPage());
      }

      if (urlPage.contains("apply_expert")) {
        if (spFunIsLogin(context: context)) {
          SPClassNavigatorUtils.spFunPushRoute(
              context, SPClassExpertApplyPage());
        }
      }

      if (urlPage.contains("big_data_report")) {
        if (spFunIsLogin(context: context)) {
          spFunGetBcwUrl("bigDataReport");
        }
      }
      if (urlPage.contains("all_analysis")) {
        if (spFunIsLogin(context: context)) {
          spFunGetBcwUrl("allAnalysis");
        }
      }

      if (urlPage.contains("odds_wave")) {
        if (spFunIsLogin(context: context)) {
          spFunGetBcwUrl("oddsWave");
        }
      }
      if (urlPage.contains("dark_horse_analysis")) {
        if (spFunIsLogin(context: context)) {
          spFunGetBcwUrl("coldJudge");
        }
      }
    } else {
      SPClassNavigatorUtils.spFunPushRoute(
          context, SPClassWebPage(urlPage, title));
    }
  }

  void spFunGetBcwUrl(String value) {
    if (spFunIsLogin(context: context)) {
      var params = SPClassApiManager.spFunGetInstance().spFunGetCommonParams();
      params.putIfAbsent("model_type", () => value);
      SPClassNavigatorUtils.spFunPushRoute(
          context,
          SPClassWebPage(
              SPClassNetConfig.spFunGetBasicUrl() +
                  "user/bcw/login?" +
                  Transformer.urlEncodeMap(params),
              ""));
    }
  }

  // spFunGetHotMatch() {
  //   SPClassApiManager.spFunGetInstance().spFunGuessMatchList<SPClassGuessMatchInfo>(queryParams: {"page": 1,"date":"","spProFetchType": "hot",'match_type':spProHomeMatchType},spProCallBack: SPClassHttpCallBack(
  //       spProOnSuccess: (list){
  //         if(mounted){
  //           setState(() {
  //             spProHotMatch=list.spProDataList.length>2?list.spProDataList.sublist(0,2):list.spProDataList;
  //           });
  //         }
  //       },onError: (v){},spProOnProgress: (v){}
  //   ));
  // }
}